﻿using System;
using System.Linq;
using Entities;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace EntityFramework
{
	[TestClass]
	public class LynnChangesJobsFinished
	{
		[TestMethod]
		public void TestNewEmployee()
		{
			DatabaseSetup.Setup();
			Change();
		}

	
		private void Change()
		{
			using (var db = new EntityFrameworkDemoEntities())
			{
				//db.ContextOptions.LazyLoadingEnabled = true;
				Employee lynn = Load(db, "lynn");
				lynn.Company1.Website = "www.microsoft.com";
				//
				lynn.Employee2 = new Employee(){Name="Robert')Drop Table employee;--",Company1 = lynn.Company1};
				lynn.Jobs.First().Status = "old";
				lynn.Jobs.Add(new Job(){Title = "Goddess of the Earth",Employee1 = lynn});
				db.DeleteObject(lynn.Events.First());
				lynn.Events.Add(new Event(){EventTitle = "Wild Party with Drinks",Employee1 = lynn});
				db.SaveChanges();
			}
		}

		private static Employee Load(EntityFrameworkDemoEntities db, string name)
		{
			return (from e in db.Employees.Include("Company1")
			        where e.Name == name
			        select e).First();
		}
	}
}